import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
import Home from '../pages/Home.vue'
const About = () => import('../pages/About.vue')
const Mime = () => import('../pages/Mime.vue')
import NotFound from '../pages/NotFound.vue'

// 配置映射关系
const routes = [
  {
    path: '/',
    redirect: '/home',
  },
  {
    path: '/home',
    component: Home,
    name: 'home',
  },
  {
    path: '/about',
    component: About,
  },
  {
    path: '/mime',
    component: Mime,
  },
  {
    path: '/:pathMatch(.*)*',
    component: NotFound,
  },
]
const router = createRouter({
  routes,
  history: createWebHistory(),
})
router.beforeEach((to, from)=>{
  // to:当前将要跳转去的route对象
  // from:现有route对象
  // 返回值：
  // 1.返回false不跳转
  // 2.返回字符串或者跳转对象{path，params，query}
  // 3.不写返回值或者返回值为undefined表示默认跳转
  if(to.path === '/about'){
    return false 
  }
  if(to.path === '/mime'){
    return '/home' 
  }
})
export default router
